package Lotr.game;

import Lotr.game.Entity.Enemy;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

public class Path {

    private static final int PATH_BORDER = 10;
    public final static int UP = 0;
    public final static int DOWN = 1;
    public final static int LEFT = 2;
    public final static int RIGHT = 3;
    //abstand vom rand + breitestes fich
    private static final int PATHWIDTH = 2*PATH_BORDER + 40;
    private List<PathPoint> pathPoints;
    private int startX, startY;
    private Level l;

    public Path(Level l) {
        this.l = l;
        pathPoints = new ArrayList<PathPoint>();
        pathPoints.add(new PathPoint(0, 20, 400, PATHWIDTH, RIGHT));
        pathPoints.add(new PathPoint(400, 20, PATHWIDTH, 150, DOWN));
        pathPoints.add(new PathPoint(400, 170, -150, PATHWIDTH, LEFT));
        pathPoints.add(new PathPoint(250, 170, PATHWIDTH, -320, UP));
        startX = -100;
        startY = 30;
    }

    public void render(Graphics g) {
        for (PathPoint pp : pathPoints) {
            pp.renderPath(g);
        }
    }
    
    public void enemyReachedEnd(Enemy e, int damage){
        l.enemyReachedEnd(e,damage);
    }

    public int getStartX() {
        return startX;
    }

    public int getStartY() {
        return startY;
    }

    public int getPathPointCount() {
        return pathPoints.size();
    }

    public PathPoint getPathPoint(int index) {
        return pathPoints.get(index);
    }

    public static class PathPoint {
        private int direction;
        private int startX, startY;
        private int width, height;
        private int directionX, directionY;
        private int endX, endY;     

        public PathPoint(int startX, int startY, int width, int height, int direction) {
            this.width = width;
            this.height = height;
            this.direction = direction;
            if (width < 0) {
                this.startX = startX + width;
                this.width *= -1;
                this.width += PATHWIDTH;
            } else {
                this.startX = startX;
            }
            if (height < 0) {
                this.startY = startY + height;
                this.height *= -1;
                this.height += PATHWIDTH;
            } else {
                this.startY = startY;
            }
            if (direction == DOWN) {
                directionY = Enemy.DOWN;
                directionX = 0;
                endX = startX + PATH_BORDER;
                endY = startY + height + PATH_BORDER;
            } else if (direction == UP) {
                directionY = Enemy.UP;
                directionX = 0;
                endX = startX + PATH_BORDER;
                endY = startY + height + PATH_BORDER;
            } else if (direction == LEFT) {
                directionX = Enemy.LEFT;
                directionY = 0;
                endX = startX + width + PATH_BORDER;
                endY = startY + PATH_BORDER;
            } else if (direction == RIGHT) {
                directionX = Enemy.RIGHT;
                directionY = 0;
                endX = startX + width + PATH_BORDER;
                endY = startY + PATH_BORDER;
            } else {
                directionX = 0;
                directionY = 0;
                endX = 0;
                endY = 0;
            }
        }
        public int getDirection() {
            return direction;
        }

        public int getDirectionX() {
            return directionX;
        }

        public int getDirectionY() {
            return directionY;
        }

        public int getEndX() {
            return endX;
        }

        public int getEndY() {
            return endY;
        }

        public void renderPath(Graphics g) {
            g.setColor(Color.WHITE);
            g.fillRect(startX, startY, width, height);
        }
    }
}
